/**
 * PopupWindow.jsx
 * 弹出窗口组件
 *
 * created by qiuwei
 * version 1.0.0
 * 2016年03月18日
 */

import React from 'react';
import * as PopupWindowStyle from './PopupWindow.less';

export default class PopupWindow extends React.Component {
	static propTypes = {
		title: React.PropTypes.string,
		visible: React.PropTypes.bool,
		requestClose: React.PropTypes.func
	};

	constructor(props) {
		super(props);
	}

	handleClose = () => {
		let { requestClose } =  this.props;
		requestClose && requestClose();
	};

	render() {
		let { title, children, visible = false } = this.props;
		let isVisible = visible ? 'block' : 'none';

		return (
			<div>
				<div className={PopupWindowStyle.popUpWindow} style={{display:isVisible}}>
					{title && <div className='title'>{title}</div>}
					<div>
						{children}
					</div>
				</div>
				{ visible && 
				<div onClick={this.handleClose} className={PopupWindowStyle.cover}></div>}
			</div>
		);
	}
}